//// demo_prog/chapter6/lec10_fgets_demo.c
// 用fgets函数替代
// 需要在终端中演示
#include<stdio.h>
int main(void)
{
    // 下面这行代码是为了在课堂演示时添加，自己运行时请将下面一行语句注释掉
    freopen("demo_prog/chapter6/lec10_gets_demo_input.txt", "r", stdin);
    
    char str1[4] = {0};
    char str2[4] = {0};    
    printf("Address of str1=%lu, str2=%lu\n", (unsigned long)str1, (unsigned long)str2);
    printf("Before input: str2 = \"%s\"\n", str2);
    // 输入一个很长的字符串到str1, 注意观察str2的值被覆盖了
    fgets(str1, 4, stdin);
    printf("After input: str1 = \"%s\"\n", str1);
    printf("str2 = \"%s\"\n", str2);
    return 0;
}